<%-- 
  -- Body Show para CustomerAccount
  --
  -- @author pablo.tortorella
--%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-html-el-1.2.8.tld" prefix="html-el"%>
<%@ taglib uri="/WEB-INF/struts-logic-el-1.2.8.tld" prefix="logic-el"%>
<%@ taglib uri="/WEB-INF/security.tld" prefix="security" %>
<%@ taglib uri="/WEB-INF/displaytag-el.tld" prefix="display" %>

<%-- Librerias para EXT library --%>
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/ext-all.css'/>" />
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/xtheme-default.css'/>" />

<script src="<html:rewrite page='/protected/script/ext-1.1.1/adapter/ext/ext-base.js'/>" type="text/javascript"></script>
<script src="<html:rewrite page='/protected/script/ext-1.1.1/ext-all.js'/>" type="text/javascript"></script>

<%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean2"%>

<%-- prototype esta en el main layout --%>
<script src="<html:rewrite page='/protected/script/scriptaculous/scriptaculous.js'/>" type="text/javascript"></script>

<script type="text/javascript">
    function showCustomerAccountDetails() {

        var accountIdObj = $("customerAccountId");
        var customerIdObj = $("customerId");
        
        accountIdObj.value = $("accountIdId").value;
        customerIdObj.value = $("customerIdId").value;
        
        var form = $("showCustomerAccountFormId");
        form.submit();
    }
    
    function preCollectDebt(debt) {
    	var debtObj = $("debtId");
    	debtObj.value = debt;
    	
    	var form = $("collectDebtFormId");
        form.submit();
    }
 </script>   

<div class="errors">
    <html:errors />
</div>

<%-- El ID del form NO debe ser modificado. Se usa desde el menu --%>
<html:form action="/protected/showCustomerAccount.do" styleId="customerAccountFormId">
    <%-- Inyectados por Javascript --%>
    <html:hidden property="customerId" name="customerAccountForm" styleId="customerIdId" />
    <h2>Cuenta Corriente de Cliente</h2>
    
    <div class="customerAccountEdit">
        <table class="tableData" cellspacing="0">
            <tr>
                <td class="tableDataTitle">
                    Nro. Cuenta
                </td>
                <td class="tableDataValue">
                    <html:text readonly="true" property="accountId" name="customerAccountForm" styleId="accountIdId" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Cliente
                </td>
                <td class="tableDataValue">
                    <html:text readonly="true" property="customerName" name="customerAccountForm" styleId="customerNameId" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Saldo
                </td>
                <td class="tableDataValue">
                    <html:text readonly="true" property="balance" name="customerAccountForm" styleId="balanceId" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Deuda Total
                </td>
                <td class="tableDataValue">
                    <html:text readonly="true" property="totalDebt" name="customerAccountForm" styleId="totalDebtId"/>
                </td>
            </tr>
        </table>
        
		<br/>
    	<h2>Deudas activas del cliente</h2>
    	
    	<logic:empty name="customerAccountForm" property="activeDebts">
    		<p>El cliente no tiene ninguna deuda activa</p>
    	</logic:empty>
    	
	    <bean:define id="debts" name="customerAccountForm" property="activeDebts" />
	    <display:table name="pageScope.debts" sort="list" export="true" pagesize="15" requestURI="/protected/showCustomerAccount.do" id="row" class="displayTable">
	        <display:column title="Cobrar" class="columnGifLink" media="html">
	            <img src="<html:rewrite page='/protected/img/money.gif'/>" alt="Cobrar" name="submitButton" onclick="preCollectDebt('<bean:write name="row" property="id" />')" title="Cobrar la deuda...">
	        </display:column>
	        <display:column title="Participante" property="student.fullName" sortable="true" />
	        <display:column title="Curso" property="course.name" sortable="true" />
	        <display:column title="Desde" property="validityFrom" sortable="true" format="{0,date,dd/MM/yyyy}"/>
	        <display:column title="Venc." property="expiry" sortable="true" format="{0,date,dd/MM/yyyy}"/>
	        <display:column title="Saldo" property="balance" sortable="true" />
	        <display:column title="Estado" property="debtStatus" sortable="true" decorator="ar.uba.fi.posgrado.common.web.util.PosgradoStatusDecorator" />
	        <display:column media="csv excel pdf" title="Descuentos y Beneficios" property="discountsAndBenefitsSummary" />
	    </display:table> 
    
        <br/>
        
        <security:securizedContent roles="administrador,secretaria,ente">
            <div class="panelButton">
                <input type="button" value="Ver Detalle" onclick="showCustomerAccountDetails();" title="Ver detalle de la cuenta corriente del cliente ..." class="button">
            </div>
        </security:securizedContent>
    </div>
</html:form>

<%-- Inyectados por Javascript. Es para mostrar el detalle de la cuenta corriente --%>
<div id="showCustomerAccountDetailsDiv" class="hideClass">
    <html:form action="/protected/showCustomerAccountDetails" styleId="showCustomerAccountFormId">
        <html:hidden property="accountId" value="" styleId="customerAccountId" />
        <html:hidden property="customerId" value="" styleId="customerId" />
    </html:form>
</div>

<%-- Inyectados por Javascript. Es para cobrar una deuda --%>
<div id="collectDebtDiv" class="hideClass">
    <html:form action="/protected/prepareCollect" styleId="collectDebtFormId">
        <html:hidden property="debtId" styleId="debtId" />
    </html:form>
</div>